/*
 * @Author: 晴鸢. 3013433857@qq.com
 * @Date: 2025-09-21 12:48:33
 * @LastEditors: 晴鸢. 3013433857@qq.com
 * @LastEditTime: 2025-09-21 13:10:40
 * @FilePath: /Learn/thread/LockGuard.hpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#pragma once
#include<pthread.h>
class Mutex
{
public:
    Mutex(pthread_mutex_t*lock)
        :_lock(lock)
        {}
    void Lock()
    {
        pthread_mutex_lock(_lock);
    }
    void Unlock()
    {
        pthread_mutex_unlock(_lock);
    }
    ~Mutex()
    {}
private:
    pthread_mutex_t *_lock;
};

class LockGuard
{
public:
    LockGuard(pthread_mutex_t*lock)
        :_mutex(lock)
    {
        _mutex.Lock();
    }
    ~LockGuard()
    {
        _mutex.Unlock();
    }
private:
    Mutex _mutex;
};

